from google.appengine.ext import db
from google.appengine.api import users

class Visitor(db.Model):
    ip = db.StringProperty()
    added_on = db.DateTimeProperty(auto_now_add=True)

class UserPrefs(db.Model):
    added_on = db.DateTimeProperty(auto_now_add=True)
    user = db.UserProperty()
    token = db.StringProperty()
    nsid = db.StringProperty()
    username = db.StringProperty()
    fullname = db.StringProperty()
    
    def getcurrentuser(self):
        user = users.get_current_user()
        if not user:
            return self;
        q = db.GqlQuery("SELECT * FROM UserPrefs WHERE user = :1", user)
        userprefs = q.get()
        return userprefs

class Comment(db.Model):
    added_on = db.DateTimeProperty(auto_now_add=True)
    nsid = db.StringProperty()
    description = db.StringProperty()
    nsid = db.StringProperty()
    tags = db.StringProperty()
    photo_id = db.StringProperty()
    
    def getrandomcomment(self, tags):
        q = db.GqlQuery("SELECT * FROM Comment WHERE tags = :1", tags)
        comment = q.get()
        return comment
